package cn.yangliu.gennerator;

import cn.yangliu.comm.tools.ReflectUtils;
import cn.yangliu.tools.FileUtils;

import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;


public class CodeTemplate {

    protected String t_entity;
    protected String t_equals;
    protected String t_equal_method;
    protected String t_extends;
    protected String t_field;
    protected String t_getter;
    protected String t_hash;
    protected String t_implement;
    protected String t_import;
    protected String t_mapper;
    protected String t_service;
    protected String t_service_impl;
    protected String t_setter;
    protected String t_setter_chain;
    protected String t_controller;
    protected String t_constructor;
    protected String t_toString;
    protected String t_if;
    protected String t_if_end;
    protected String t_controller_delete;
    protected String t_controller_getById;
    protected String t_controller_insert;
    protected String t_controller_list;
    protected String t_controller_update;

    public CodeTemplate() {
        List<Field> fields = ReflectUtils.getFields(CodeTemplate.class, Object.class);
        fields.parallelStream().forEach(f -> {
            if (!Modifier.isStatic(f.getModifiers())) {
                try (InputStream is = CodeTemplate.class.getClassLoader().getResourceAsStream("templates/" + f.getName() + ".java")) {
                    String temp = FileUtils.read(is, true);
                    ReflectUtils.setValueByField(f, this, temp);
                } catch (Exception e) {
                    throw new RuntimeException(e.getMessage(), e);
                }
            }
        });
    }

    public String getT_entity() {
        return t_entity;
    }

    public void setT_entity(String t_entity) {
        this.t_entity = t_entity;
    }

    public String getT_equals() {
        return t_equals;
    }

    public void setT_equals(String t_equals) {
        this.t_equals = t_equals;
    }

    public String getT_equal_method() {
        return t_equal_method;
    }

    public void setT_equal_method(String t_equal_method) {
        this.t_equal_method = t_equal_method;
    }

    public String getT_extends() {
        return t_extends;
    }

    public void setT_extends(String t_extends) {
        this.t_extends = t_extends;
    }

    public String getT_field() {
        return t_field;
    }

    public void setT_field(String t_field) {
        this.t_field = t_field;
    }

    public String getT_getter() {
        return t_getter;
    }

    public void setT_getter(String t_getter) {
        this.t_getter = t_getter;
    }

    public String getT_hash() {
        return t_hash;
    }

    public void setT_hash(String t_hash) {
        this.t_hash = t_hash;
    }

    public String getT_implement() {
        return t_implement;
    }

    public void setT_implement(String t_implement) {
        this.t_implement = t_implement;
    }

    public String getT_import() {
        return t_import;
    }

    public void setT_import(String t_import) {
        this.t_import = t_import;
    }

    public String getT_mapper() {
        return t_mapper;
    }

    public void setT_mapper(String t_mapper) {
        this.t_mapper = t_mapper;
    }

    public String getT_service() {
        return t_service;
    }

    public void setT_service(String t_service) {
        this.t_service = t_service;
    }

    public String getT_service_impl() {
        return t_service_impl;
    }

    public void setT_service_impl(String t_service_impl) {
        this.t_service_impl = t_service_impl;
    }

    public String getT_setter() {
        return t_setter;
    }

    public void setT_setter(String t_setter) {
        this.t_setter = t_setter;
    }

    public String getT_setter_chain() {
        return t_setter_chain;
    }

    public void setT_setter_chain(String t_setter_chain) {
        this.t_setter_chain = t_setter_chain;
    }

    public String getT_controller() {
        return t_controller;
    }

    public void setT_controller(String t_controller) {
        this.t_controller = t_controller;
    }

    public String getT_constructor() {
        return t_constructor;
    }

    public void setT_constructor(String t_constructor) {
        this.t_constructor = t_constructor;
    }

    public String getT_toString() {
        return t_toString;
    }

    public void setT_toString(String t_toString) {
        this.t_toString = t_toString;
    }

    public String getT_if() {
        return t_if;
    }

    public void setT_if(String t_if) {
        this.t_if = t_if;
    }

    public String getT_if_end() {
        return t_if_end;
    }

    public void setT_if_end(String t_if_end) {
        this.t_if_end = t_if_end;
    }

    public String getT_controller_delete() {
        return t_controller_delete;
    }

    public void setT_controller_delete(String t_controller_delete) {
        this.t_controller_delete = t_controller_delete;
    }

    public String getT_controller_getById() {
        return t_controller_getById;
    }

    public void setT_controller_getById(String t_controller_getById) {
        this.t_controller_getById = t_controller_getById;
    }

    public String getT_controller_insert() {
        return t_controller_insert;
    }

    public void setT_controller_insert(String t_controller_insert) {
        this.t_controller_insert = t_controller_insert;
    }

    public String getT_controller_list() {
        return t_controller_list;
    }

    public void setT_controller_list(String t_controller_list) {
        this.t_controller_list = t_controller_list;
    }

    public String getT_controller_update() {
        return t_controller_update;
    }

    public void setT_controller_update(String t_controller_update) {
        this.t_controller_update = t_controller_update;
    }
}
